<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8" />
		<title>Home</title>
	</head>
	<body>
		
		<script th:inline="javascript">
			var url='ws://'+location.host+[[@{/marco}]];
			var sock=new WebSocket(url);
			
			sock.onopen=function(){
				console.log('Opening');
				sayMarco();
			}
			
			sock.onmessage=function(e) {
				console.log('Recieve message:'+e.data);
				setTimeout(function(){sayMarco();},2000);
			}
			
			sock.onclose=function () {
				console.log('Closing');
			}
			
			function sayMarco () {
				console.log('Sending Marco!');
				sock.send("Marco!");
			}
			
		</script>
		
	</body>
</html>
